

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>家居家具管理系统</title>

    <!-- begin::global styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/bundle.css" type="text/css">
    <!-- end::global styles -->

    <!-- begin::dropzone -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/dropzone/dropzone.css" type="text/css">
    <!-- begin::dropzone -->

    <!-- begin::select2 -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/select2/css/select2.min.css" type="text/css">
    <!-- end::select2 -->

    <!-- begin::tagsinput -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/tagsinput/bootstrap-tagsinput.css" type="text/css">
    <!-- end::tagsinput -->

    <!-- begin::lightbox -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/lightbox/magnific-popup.css" type="text/css">
    <!-- end::lightbox -->

    <!-- begin::custom styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/css/app.css" type="text/css">
    <link rel="stylesheet" href="${APP_PATH}/assets/css/custom.css" type="text/css">
    <!-- end::custom styles -->

</head>
<body>

<!-- begin::page loader-->
<div class="page-loader">
    <div class="page-loader">
        <div class="spinner-border text-primary"></div>
        <span>加载中 ...</span>
    </div>
</div>
<!-- end::page loader -->

<!-- begin::navigation -->
<jsp:include page="/WEB-INF/jsps/Manager/common/navigation.jsp"/>
<!-- end::navigation -->

<!-- begin::top -->
<jsp:include page="/WEB-INF/jsps/Manager/common/top.jsp"/>
<!-- end::top -->

<!-- begin::main content -->
<main class="main-content">

    <div class="container-fluid">

        <!-- begin::page header -->
        <div class="page-header d-md-flex justify-content-between align-items-center">
            <h4>${requestScope.furniture.fname}</h4>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb m-t-0">
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toManager">首页</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toMyGoods">我的商品</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toKindsType?kid=${requestScope.kinds.kid}">${requestScope.kinds.kname}</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toFurniture?kid=${requestScope.kinds.kid}&ktid=${requestScope.kindsType.ktid}&target=${requestScope.target}&pageNo=${requestScope.pageNo}">${requestScope.kindsType.ktname}</a></li>
                    <li class="breadcrumb-item active" aria-current="page">${requestScope.furniture.fname}</li>
                </ol>
            </nav>
        </div>
        <!-- end::page header -->


        <jsp:include page="/WEB-INF/jsps/Manager/furniture_detail/furnitureInfoAndFace.jsp"/>

        <jsp:include page="/WEB-INF/jsps/Manager/furniture_detail/view.jsp"/>

        <jsp:include page="/WEB-INF/jsps/Manager/furniture_detail/detail.jsp"/>

        <jsp:include page="/WEB-INF/jsps/Manager/furniture_detail/furnitureKinds.jsp"/>

        <!-- begin::bottom -->
        <div class="card-group">
            <jsp:include page="/WEB-INF/jsps/Manager/common/bottom.jsp"/>
        </div>
        <!-- end::bottom -->


    </div>




</main>
<!-- end::main content -->


<!-- begin::global scripts -->
<script src="${APP_PATH}/assets/vendors/bundle.js"></script>
<!-- end::global scripts -->

<!-- begin::dropzone -->
<script src="${APP_PATH}/assets/vendors/dropzone/dropzone.js"></script>
<!-- end::dropzone -->

<!-- begin::select2 -->
<script src="${APP_PATH}/assets/vendors/select2/js/select2.min.js"></script>
<script src="${APP_PATH}/assets/js/examples/select2.js"></script>
<!-- end::select2 -->

<!-- begin::input mask -->
<script src="${APP_PATH}/assets/vendors/tagsinput/bootstrap-tagsinput.js"></script>
<script src="${APP_PATH}/assets/js/examples/tagsinput.js"></script>
<!-- end::input mask -->

<!-- begin::lightbox -->
<script src="${APP_PATH}/assets/vendors/lightbox/jquery.magnific-popup.min.js"></script>
<script src="${APP_PATH}/assets/js/examples/lightbox.js"></script>
<!-- end::lightbox -->

<!-- begin::swiper -->
<script src="${APP_PATH}/assets/vendors/swiper/swiper.min.js"></script>
<script src="${APP_PATH}/assets/js/examples/swiper.js"></script>
<!-- end::swiper -->

<!-- begin::custom scripts -->
<script src="${APP_PATH}/assets/js/custom.js"></script>
<script src="${APP_PATH}/assets/js/app.js"></script>
<!-- end::custom scripts -->


</body>
</html>
<script>
    $(function () {
        $(document).bind("contextmenu",function(e){
            return false;
        });

        $("#fname").on("keyup blur",function () {
            validationNull("#fname");
        });

        $("#fprice").on("keyup",function () {
            var oEvent = window.event;
            var keyCode = oEvent.keyCode;
            if (keyCode!=17){
                validationNull("#fprice");
            }
            validationNumAndDecimal("#fprice",false,"k");
        }).on("blur", function () {
            validationNull("#fprice");
            validationNumAndDecimal("#fprice",false,"b");
        });
        validationRender();
    });


    function validationRender() {
        $("input[name = 'fkname']").on("keyup blur",function () {
            var id = $(this).attr("id");
            validationNull("#"+id);
            validationExist(id);
        });

        $("input[name = 'fkprice'],input[name = 'cost']").on("keyup",function () {
            var id = $(this).attr("id");
            var oEvent = window.event;
            var keyCode = oEvent.keyCode;
            if (keyCode!=17){
                validationNull("#"+id);
            }
            validationNumAndDecimal("#"+id,false,"k");
        }).on("blur", function () {
            var id = $(this).attr("id");
            validationNull("#"+id);
            validationNumAndDecimal("#"+id,false,"b");
        });

        $("input[name = 'stock']").each(function () {
            var id = $(this).attr("id");
            $(this).on("keyup blur", function () {
                var oEvent = window.event;
                var keyCode = oEvent.keyCode;
                if (keyCode != 17) {
                    validationNull("#" + id);
                }
                validationNumAndDecimal("#" + id,true,'k');
            });
       });
    }

    function validationNull(id) {
        var newName = $(id).val();
        if(newName ==''){
            $(id).next(".invalid-feedback").html("这是必填字段哦~");
            $(id).removeClass("is-valid");
            $(id).addClass("is-invalid");
            return true;
        }else{
            $(id).removeClass("is-invalid");
            $(id).addClass("is-valid");
            return false;
        }
    }

    function validationExist(id) {
        var isExist = false;
        var newFkname = $("#"+id).val();
        $("input[name = 'fkname']").each(function () {
            var this_id = $(this).attr("id");
            var fkname = $(this).val();
            if(id == this_id){
                return true;
            }else {
                if(newFkname != "" && newFkname == fkname){
                    $("#"+id).next(".invalid-feedback").html("这个名称您已经起过了哦~");
                    $("#"+id).removeClass("is-valid");
                    $("#"+id).addClass("is-invalid");
                    isExist = true;
                }
            }
        });
        return isExist;
    }

    function validationNumAndDecimal(id,isInteger,kORb) {
        var  incomplete = false;
        var regex = /^\d+(\.\d{0,2})?$/ ;
        var errorMessage = "只能输入整数和小数哦~（小数只能保留两位）";
        var content = $(id).val();
        $(id).css("ime-mode", "disabled"); //CSS设置输入法不可用;
        if(kORb=='b'){
            regex = /^\d+(\.\d{1,2})?$/ ;
            errorMessage = "您好像还没有写完哦~";
        }
        if(isInteger){
            regex = /^\d+$|^\d+[.]?\d+$/ ;
            errorMessage = "只能输入整数哦~";
        }
        if(!validationNull(id)){
            if(!regex.test(content)){
                $(id).next(".invalid-feedback").html(errorMessage);
                $(id).removeClass("is-valid");
                $(id).addClass("is-invalid");
                if(kORb == 'b'){
                    incomplete = true;
                }else {
                    $(id).val("");
                }
            }else{
                incomplete = false;
            }
        }
        return incomplete;
    }
</script>
<script>
$(function () {
    getFurnitureInfo();
    //getFurnitureFace();
    getBgColor("#bg");
    getViewList();
    getDetailList();
    getFKList();
    fileMap.set(1,null);
    fileMap.set(2,null);
    var flag = false;
    if(${requestScope.furniture.condition == 1}){
        flag = true;
    }
    $("#condition").prop("checked",flag).change(function () {
       setCondition();
    });
});

var fileNum = 0;
var fileMap = new Map();
var fileDeleteUrl = null;
var multiple = true;
var ableToMarket = true;
var myDropzone = null;

function setFace(i) {
    multiple = false;
    fileNum = i;
}

function setView() {
    multiple = true;
    fileDeleteUrl = "${APP_PATH}/view/fileDelete";
}

function setDetail() {
    multiple = true;
    fileDeleteUrl = "${APP_PATH}/detail/fileDelete";
}


function getFurnitureDetail() {
    $.ajax({
        url : "${APP_PATH}/furniture/getFurnitureDetail",
        method : "POST",
        data : {
            fid : ${requestScope.furniture.fid}
        },
        success : function (result) {
            if (result.success) {
                var viewList = result.data.viewList;
                var detailList = result.data.detailList;
                var furnitureKindsList = result.data.furnitureKindsList;
                if(viewList.length != 0 && detailList.length != 0 && furnitureKindsList.length != 0){
                    ableToMarket = true;
                }else{
                    ableToMarket = false;
                }
            }
        },
        complete : function () {
            if(!ableToMarket){
                if($("#condition").prop("checked") == true){
                    $("#condition").prop("checked",false);
                    setCondition();
                }
                swal("由于缺乏必要信息，该商品已被下架！", {icon: "warning"});
                $("#condition").attr("disabled","disabled");
            }else {
                $("#condition").removeAttr("disabled");
            }
        }
    });
}

function getBgColor(id) {
    var num = randomNum(0,4);
    switch(num){
        case 0:
            $(id).addClass("bg-primary-bright");
            break;
        case 1:
            $(id).addClass("bg-danger-bright");
            break;
        case 2:
            $(id).addClass("bg-success-bright");
            break;
        case 3:
            $(id).addClass("bg-warning-bright");
            break;
        case 4:
            $(id).addClass("bg-info-bright");
            break;
    }
    }

function randomNum(minNum,maxNum){
    switch(arguments.length){
        case 1:
            return parseInt(Math.random()*minNum+1);
            break;
        case 2:
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum);
            break;
        default:
            return 0;
            break;
    }
}

</script>


